# ① 构建阶段
FROM maven:3.9.6-eclipse-temurin-17 AS build
WORKDIR /app

# 复制 settings 到临时位置，再放到 /root/.m2
COPY mvn-settings.xml /tmp/settings.xml
RUN mkdir -p /root/.m2 && cp /tmp/settings.xml /root/.m2/settings.xml

COPY pom.xml .
COPY src ./src

# 只缓存仓库目录，不覆盖 settings.xml
RUN --mount=type=cache,target=/root/.m2/repository \
    mvn -s /root/.m2/settings.xml -B -U -DskipTests \
        -Dmaven.wagon.http.retryHandler.count=5 \
        -Dmaven.wagon.http.pool=false \
        clean package

# ② 运行阶段
FROM eclipse-temurin:17-jdk
WORKDIR /app
COPY --from=build /app/target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/app/app.jar"]
